package com.cskaoyan.demo;

import com.cskaoyan.opensource.C3p0Utils;
import com.cskaoyan.opensource.DBCPUtils;
import com.cskaoyan.opensource.DruidUtils;
import com.cskaoyan.pool.MyConnectionPoolV1;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * 创建日期: 2022/11/18 10:04
 *
 * @author ciggar
 */
public class QueryDemo {

    public static void main(String[] args) throws SQLException {

        // 1. 从数据库连接池获取连接
        Connection connection = DruidUtils.getConnection();


        // 2. 使用连接对象去执行操作
        PreparedStatement preparedStatement = connection.prepareStatement("select * from account where id = ?");
        preparedStatement.setInt(1,1002);

        ResultSet resultSet = preparedStatement.executeQuery();
        while (resultSet.next()) {
            int id = resultSet.getInt("id");
            String name = resultSet.getString("name");
            int money = resultSet.getInt("money");
            System.out.println(id + " : " + name + " : " + money);
        }

        // 3. 关闭资源
        resultSet.close();
        preparedStatement.close();
        // JDBC4Connection
        connection.close();

        // MyConnectionPoolV1.returnConnection(connection);

    }
}
